package cc.ufinity.networkdiagnose.widget;

import cc.ufinity.networkdiagnose.adapter.GridAdapter;
import cc.ufinity.networkdiagnose.view.R;
import android.app.Activity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ListAdapter;
import android.widget.AdapterView.OnItemClickListener;

public class SettingWidget extends GeneralTestWidget {
    private GridView setGridView;
    private Activity ctx;

    public SettingWidget(Activity context) {
        super(context);
        this.ctx = context;
        inflate(context, R.layout.setting_widget, this);
        setGridView = (cc.ufinity.networkdiagnose.view.MyGridView) this.findViewById(R.id.settingGridView);
        String[] menu = getResources().getStringArray(R.array.settingGridView);
        int[] icons = new int[] { R.drawable.ftp_settings, R.drawable.people, R.drawable.phone };
        ListAdapter adapter = new GridAdapter(ctx, icons, menu);
        setGridView.setAdapter(adapter);
        setGridView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View v, int index, long id) {
                switch (index) {
                case 0:
                    ftpConfig();
                    break;
                case 1:
                    accountConfig();
                    break;
                case 2:
                    mobileConfig();
                    break;
                }
            }
        });
    }

    private void mobileConfig() {
        MyMobileCfgWidget mw = new MyMobileCfgWidget(ctx);
        ctx.setContentView(mw);
    }

    private void ftpConfig() {
        FtpConfigWidget fw = new FtpConfigWidget(ctx);
        ctx.setContentView(fw);
    }

    private void accountConfig() {
        AccountConfigWidget af = new AccountConfigWidget(ctx);
        ctx.setContentView(af);
    }

}
